import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
		uuid:'',
		city:'',
		oldCity:'',
        login: false,
		terminalType:'none', // hotel (酒店客户端端) cleaner (保洁员客户端)
        token: '',  
		open_id:'',
		username:'',
		avatarUrl:'/static/login/avatarUrl.png',
		balance:'',
		phone:'',
		address:'',
		title:'',
		tab:'1',
		cleaner:{
			dds:0,//待打扫
			dqr:0//待确认
		},
		hotel:{
			djd:0,//待接单
			dds:0,//待打扫
			dqr:0//带确认
		},
		haveNews:0//消息提示
    },
	actions:{
		changeTabIndex({commit}, index) {
			commit('changeTab', index)    // 提交到mutations中处理    
		}
	},
    mutations: {  
        login(state, provider) { 
            state.login = true;
			state.title = provider.say; 
			state.address = provider.address; 
			state.username = provider.username; 
			state.avatarUrl = provider.head_images;  
			state.terminalType = provider.type == 1?'cleaner':'hotel';
			state.phone = provider.phone;
			if(provider.adress) state.adress = provider.adress;
        
		},
		changeType(state,type){
			/**
			 * type 1 为保洁端  type 2 为酒店端
			 */
			if(type == "1"){
				state.terminalType = 'cleaner';
	
			}else if(type == "2"){
				state.terminalType = 'hotel';
				
			}else{
				state.terminalType = 'none';
			}
		},
		changeTab(state,index){
			state.tab = index;
		},
        logout(state) {
            state.login = false;
            state.avatarUrl = '';  
            state.terminalType = 0;
            state.phone = '';
            state.adress = '';
			state.title = '';
			state.address = '';
			state.username = '';
        },
		changeCleanerOrder(state,provider){
			let key = provider.key;
			let value = provider.value;
			state.cleaner[key] = value;
		},
		changeHotelOrder(state,provider){
			let key = provider.key;
			let value = provider.value;
			state.hotel[key] = value;
		},
		changeNews(state,num){
			state.haveNews = num;
		}
    }  
})

export default store